define(["jquery","template",
	"scprit/nutrition/app/courseLibrary/editCourseLibrary.servers.js",
	"scprit/nutrition/template/courseLibrary/editCourseLibrary.tpl.js"],
	function ($,template,$servers,tpl) {
    var ui = {};

    var drawCourseLibirayTab = function(data){
    	return template("editCourseLibiray_courseLibirayTab",data);
    }
    var drawModifyCourseClassifyForm = function(data){
    	return template("editCourseLibiray_modifyCourseClassifyForm",data);
    }
    var drawAddCourseForm = function(data){
        return template("editCourseLibiray_addCourseForm",data);
    }
    var drawContextMenu = function(data){
        return template("editCourseLibiray_contextMenu",data);
    }
    var drawCourseInfo = function(data){
    	return template("editCourseLibiray_courseInfo",data);
    }
    var drawFoodLibirayTab = function(data){
    	return template("editCourseLibiray_foodLibirayTab",data);
    }
    var drawCourseNutrients = function(data){
    	return template("editCourseLibiray_courseNutrients",data);
    }
    var drawAddCourseNutrients  = function(data){
    	return template("editCourseLibiray_addCourseNutrients",data);
    }
    var drawCourseFood = function(data){
    	return template("editCourseLibiray_courseFood",data);
    }
    var drawAddCoursePeriod = function(data){
    	return template("editCourseLibiray_addCoursePeriod",data);
    }
    var drawAddCoursePeriodLi = function(data){
    	return template("editCourseLibiray_addCoursePeriodLi",data);
    }
    var drawCourseLibirayWrap = function(data){
        return template("editCourseLibiray_courseLibirayWrap",data);
    }
    var drawFoodConsumption  = function(data){
        return template("course_foodConsumption",data);
    }

    ui.courseLibirayTabInit = function(options){
    	$("#" + options.id).html( tpl.courseLibirayTab() );
        var html = drawCourseLibirayTab(options);
        $("#" + options.id).html(html);
    }
    ui.modifyCourseClassifyFormInit = function(options){
    	options.dom.html( tpl.modifyCourseClassifyForm() );
        var html = drawModifyCourseClassifyForm(options);
        options.dom.html(html);
    }
    ui.addCourseFormInit = function(options){
        var data = {};
        if(options.data) data = $.extend(data,options.data);
        options.dom.html( tpl.addCourseForm() );
        var html = drawAddCourseForm(data);
        options.dom.html(html);
    }
    ui.contextMenu = function(options){
        $("#" + options.id).html( tpl.contextMenu() );
        var html = drawContextMenu(options);
        $("#" + options.id).html(html);
    }
    ui.courseInfoInit = function (options) {
        $("#" + options.id).html( tpl.courseInfo() );
        var html = drawCourseInfo(options);
        $("#" + options.id).html(html);
    };
    ui.foodLibirayTabInit = function(options){
    	$("#" + options.id).html( tpl.foodLibirayTab() );
        var html = drawFoodLibirayTab(options);
        $("#" + options.id).html(html);
    }
    ui.courseNutrientsInit = function(options){
    	$("#" + options.id).html( tpl.courseNutrients() );
        var html = drawCourseNutrients(options);
        $("#" + options.id).html(html);
    }
    ui.addCourseNutrientsInit = function(options){
    	options.dom.html( tpl.addCourseNutrients() );
        var html = drawAddCourseNutrients(options);
        options.dom.html(html);
    }
    ui.courseFoodInit = function(options){
    	$("#" + options.id).html( tpl.courseFood() );
        var html = drawCourseFood($servers.handleCoursePeriod(options.list,options.courseVersionId));
        $("#" + options.id).html(html);
    }
    ui.addCoursePeriodInit = function(options){
    	options.dom.html( tpl.addCoursePeriod() );
        var html = drawAddCoursePeriod($servers.handleAddCoursePeriod(options.list));
        options.dom.html(html);
    }
    ui.addCoursePeriodLiInit = function(options){
    	$("#" + options.id).append( tpl.addCoursePeriodLi() );
        var html = drawAddCoursePeriodLi($servers.handleAddCoursePeriodLi());
        $("#" + options.id).append(html);
    }
    ui.courseLibirayWrap = function(options){
        $("#" + options.id).html( tpl.courseLibirayWrap() );
        var html = drawCourseLibirayWrap(options);
        $("#" + options.id).html(html);
    }
    ui.foodConsumptionInit = function(options){
        $(options.dom).html( tpl.foodConsumption() );
        var html = drawFoodConsumption(options.data);
        $(options.dom).html(html);
    }
    return ui;
});